#include <bits/stdc++.h>
using namespace std;
int n, cnt;
char ch;
string s;
map <string, int> m;
string scan() {
	string a;
	cin >> ch;
	while(ch >= '0' && ch <= '9') {
		a += ch;
		cin >> ch;
	} 
	return a;
} 
int num(string s) {
	int ans = 0;
	for(int i = 0; i < s.size(); i++)
		ans = ans * 10 + (s[i] - '0');
	return ans;
} 
bool judge1(string s) {
	if(s[0] == '-') return 0;
	if(s.size() != 1 && s[0] == '0') return 0;
	if(num(s) > 255) return 0;
	return 1;
} 
bool judge2(string s) {
	if(s[0] == '-') return 0;
	if(s.size() != 1 && s[0] == '0') return 0;
	if(num(s) > 65535) return 0;
	return 1;
} 
int main() {
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> s;
		if(s == "Server") {
			string sx, sy[6], a, b, c, d, e, s1;
			int cnt = 0;
			cin >> sx;
			for(int j = 0; j < sx.size(); j++) {
				if(sx[j] < '0' || sx[j] > '9') cnt++;
				else sy[cnt] += sx[j];
				if(cnt > 5) break;
			} 
			a = sy[0], b = sy[1],  c = sy[2], d = sy[3], e = sy[4];
			if(!(judge1(a) && judge1(b) && judge1(c) && judge1(d) && judge2(e))) {cout << "ERR\n"; continue;}
			s1 = a + '.' + b + '.' + c + '.' + d + ':' + e;
			if(!m[s1]) cout << "OK\n", m[s1] = i;
			else cout << "FAIL\n";
		} 
		else {
			string sx, sy[6], a, b, c, d, e, s1;
			int cnt = 0;
			cin >> sx;
			for(int j = 0; j < sx.size(); j++) {
				if(sx[j] < '0' || sx[j] > '9') cnt++;
				else sy[cnt] += sx[j];
				if(cnt > 5) break;
			} 
			a = sy[0], b = sy[1],  c = sy[2], d = sy[3], e = sy[4];
			if(!(judge1(a) && judge1(b) && judge1(c) && judge1(d) && judge2(e))) {cout << "ERR\n"; continue;}
			s1 = a + '.' + b + '.' + c + '.' + d + ':' + e;
			if(!m[s1]) cout << "FAIL\n";
			else cout << m[s1] << endl;
		} 
	} 
	return 0;
} 
/*
2
Server 111.118044.102:1215928:
Server 37.147.111.163:10270
*/
